import java.util.*;
import java.io.*;

public class StudentReader
{
    private static ArrayList<Student> students = new ArrayList<Student>();
    private final static String S = File.separator;
    
    public static ArrayList<Student> getStudents()
    {
        return students;
    }
    
    public static void readStudents()
    {
        String filename = "studentlibrary.atd";
        try
        {
            BufferedReader reader = new BufferedReader(new FileReader(new File("libraries" + S + filename)));
            String read = "";
            reader.readLine(); //disposes first line
            do
            {
                try
                {
                    read = reader.readLine();
                    if(read != null)
                    {
                        String[] bits = read.split(",");
                        students.add(parseFromString(bits));
                    }
                }
                catch (Exception e)
                {
                }
            } while(read != null);
            reader.close();
        }
        catch (Exception e)
        {
        }
    }
    
    public static Student parseFromString(String[] parts)
    {
        int plt = 10;
        try
        {
            plt = Integer.parseInt(parts[0]);
        }
        catch (NumberFormatException e) { }
        String last = parts[1];
        String first = parts[2];
        int id = Integer.parseInt(parts[3]);
        boolean male = parts[4].equals("MALE");
        int grade = Integer.parseInt(parts[5]);
        int ns = Integer.parseInt(parts[6]);
        return (new Student(plt,last,first,id,male,grade,ns));
    }
}